#pragma once

#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <winsock2.h>

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
struct	IocpProcessThread;

class _ZMainApi	Iocp
{
public:
	Iocp();
	~Iocp();
	bool	create(DWORD numConcurrentThreads = 0);
	void	destroy();
	bool	associate(SOCKET so, ULONG_PTR completionKey);
	bool	associate(HANDLE hDevice, ULONG_PTR completionKey);
	BOOL	postCompletionStatus(ULONG_PTR completionKey, DWORD dwBytesTransferred = 0, LPOVERLAPPED pOverlapped = 0);
	BOOL	getCompletionStatus(PULONG_PTR pCompletionKey, LPDWORD pdwBytesTransferred, LPOVERLAPPED* ppOverlapped);
	bool	createThreadPool(IocpProcessThread* pProcessThread, size_t numPooledThread = 0);
	void	destroyThreadPool();

private:
	HANDLE	mIocp;
	typedef	boost::shared_ptr<boost::thread_group>	ThreadPoolPtr;
	ThreadPoolPtr		mThreadPool;
};

}